package com.zyf.wjy.dao;

import com.fasterxml.jackson.core.type.TypeReference;
import com.zyf.wjy.entity.GrowthMonitor;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 生长监测DAO
 */
@Repository
public class GrowthMonitorDao extends BaseDao<GrowthMonitor> {
    
    @Override
    protected String getFileName() {
        return "growth_monitors.json";
    }
    
    @Override
    protected TypeReference<List<GrowthMonitor>> getTypeReference() {
        return new TypeReference<List<GrowthMonitor>>() {};
    }
    
    @Override
    protected Long getId(GrowthMonitor entity) {
        return entity.getId();
    }
    
    @Override
    protected void setId(GrowthMonitor entity, Long id) {
        entity.setId(id);
    }
    
    /**
     * 根据地块ID查询
     */
    public List<GrowthMonitor> findByFieldId(Long fieldId) {
        return findAll().stream()
            .filter(monitor -> fieldId.equals(monitor.getFieldId()))
            .toList();
    }
    
    /**
     * 根据作物ID查询
     */
    public List<GrowthMonitor> findByCropId(Long cropId) {
        return findAll().stream()
            .filter(monitor -> cropId.equals(monitor.getCropId()))
            .toList();
    }
}

